package QuanLyKhachHang;

import KetNoiSQL.KetNoiSQL;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class DanhSachKhachHang extends javax.swing.JPanel {

    private DefaultTableModel modelKhachHang = new DefaultTableModel();
    Vector vLay = new Vector();

    public DanhSachKhachHang() {
        initComponents();
        try {
            vLay = KhachHang.xemDanhSachKhachHang();
            this.taiDanhSachKhachHang(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachKhachHang.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
    //Tải bảng lên

    public void taiDanhSachKhachHang(Vector vLay) throws SQLException {
        modelKhachHang.setRowCount(0);
        Vector cotKhachHang = new Vector();
        cotKhachHang.addElement("Mã");
        cotKhachHang.addElement("Tên khách hàng");
        cotKhachHang.addElement("Loai khách hàng");
        cotKhachHang.addElement("SDT");
        cotKhachHang.addElement("Fax");
        cotKhachHang.addElement("Email");
        cotKhachHang.addElement("Địa chỉ");
        cotKhachHang.addElement("Quan hệ");
        modelKhachHang.setColumnIdentifiers(cotKhachHang);

        KhachHang kh = new KhachHang();
        for (int i = 0; i < vLay.size(); i++) {
            kh = (KhachHang) vLay.get(i);

            Vector hangKhachHang = new Vector();
            hangKhachHang.addElement(kh.getMaKhachHang());
            hangKhachHang.addElement(kh.getTenKhachHang());
            hangKhachHang.addElement(kh.getLoaiKhachHang());;
            hangKhachHang.addElement(kh.getSoDT());
            hangKhachHang.addElement(kh.getFax());
            hangKhachHang.addElement(kh.getEmail());
            hangKhachHang.addElement(kh.getDiaChi());
            hangKhachHang.addElement(kh.getQuanHe());
            modelKhachHang.addRow(hangKhachHang);
        }
        tbDanhSachKhachHang.setModel(modelKhachHang);
    }

    //Cập nhật Khách hàng
    public void capNhatKhachHang() {
        int kt = 0;
        int r = tbDanhSachKhachHang.getSelectedRow();
        if (r < 0) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn mục để cập nhật", "Thông báo", JOptionPane.ERROR_MESSAGE);
            return;
        }
        KhachHang kh = new KhachHang();

        int maKhachHang = Integer.parseInt(tbDanhSachKhachHang.getValueAt(r, 0).toString().trim());
        kh.setMaKhachHang(maKhachHang);
        if (tbDanhSachKhachHang.getValueAt(r, 1).toString().equals("")) {
            JOptionPane.showMessageDialog(this, "Bạn không được để trống mục tên khách hàng", "Thông báo", JOptionPane.ERROR_MESSAGE);
            try {
                vLay = KhachHang.xemDanhSachKhachHang();
                this.taiDanhSachKhachHang(vLay);
            } catch (SQLException ex) {
                Logger.getLogger(DanhSachKhachHang.class.getName()).log(Level.SEVERE, null, ex);
            }

            return;
        }
        kh.setTenKhachHang(tbDanhSachKhachHang.getValueAt(r, 1).toString().trim());
        kh.setLoaiKhachHang(tbDanhSachKhachHang.getValueAt(r, 2).toString().trim());
        kh.setSoDT(tbDanhSachKhachHang.getValueAt(r, 3).toString().trim());
        kh.setFax(tbDanhSachKhachHang.getValueAt(r, 4).toString().trim());
        kh.setEmail(tbDanhSachKhachHang.getValueAt(r, 5).toString().trim());
        kh.setDiaChi(tbDanhSachKhachHang.getValueAt(r, 6).toString().trim());
        kh.setQuanHe(tbDanhSachKhachHang.getValueAt(r, 7).toString().trim());

        try {
            kt = KhachHang.capNhatKhachHang(kh);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Cập nhật thành công  !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                vLay = KhachHang.xemDanhSachKhachHang();
                this.taiDanhSachKhachHang(vLay);
            } else {
                JOptionPane.showMessageDialog(this, "Cập nhật bị lỗi.Xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    //Xóa Khách hàng
    public void xoaKhachHang() {
        int r = tbDanhSachKhachHang.getSelectedRow();
        if (r < 0) {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn mục để xóa", "Thông báo", JOptionPane.ERROR_MESSAGE);
            return;
        }
        int show = JOptionPane.showConfirmDialog(this, "Bạn có đồng ý xóa dữ liệu khách hàng?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (show == JOptionPane.YES_OPTION) {
            int kt = 0, dem = 0;
            int[] rArr = tbDanhSachKhachHang.getSelectedRows();
            try {
                for (int i = 0; i < rArr.length; i++) {
                    kt = KhachHang.xoaKhachHang(tbDanhSachKhachHang.getValueAt(rArr[i], 1).toString());
                    if (kt == 1) {
                        dem++;
                    }
                }
                if (dem > 0) {
                    JOptionPane.showMessageDialog(this, "Xóa " + dem + " Khách hàng", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                    vLay = KhachHang.xemDanhSachKhachHang();
                    this.taiDanhSachKhachHang(vLay);
                } else {
                    JOptionPane.showMessageDialog(this, "Không xóa được!", "Thông báo", JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        }
    }

    //tìm kiếm khách hàng
    public void timKhachHang() throws SQLException {
        if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText().equals("") && !rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            JOptionPane.showMessageDialog(null, "Bạn phải chọn ít nhất một điều kiện để tìm kiếm");
            return;
        }
        Vector vlist = new Vector();
        if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText().equals("") && !rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement(txtTenKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKTenKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText() != "" && !rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKLoaiKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText().equals("") && rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement("Quen");
            vLay = KhachHang.timKiem("spTKQuanHe", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText().equals("") && !rdQuen.isSelected() && rdKhongQuen.isSelected()) {
            vlist.addElement("Không Quen");
            vLay = KhachHang.timKiem("spTKQuanHe", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText() != "" && !rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement(txtTenKhachHang.getText().trim());
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKTen_LoaiKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText().equals("") && rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement("Quen");
            vlist.addElement(txtTenKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKQuanHe_TenKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText().equals("") && !rdQuen.isSelected() && rdKhongQuen.isSelected()) {
            vlist.addElement("Không Quen");
            vlist.addElement(txtTenKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKQuanHe_TenKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText() != "" && rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vlist.addElement("Quen");
            vLay = KhachHang.timKiem("spTKQuanHe_LoaiKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText().equals("") && txtLoaiKhachHang.getText() != "" && !rdQuen.isSelected() && rdKhongQuen.isSelected()) {
            vlist.addElement("Không Quen");
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKQuanHe_LoaiKhachHang", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText() != "" && rdQuen.isSelected() && !rdKhongQuen.isSelected()) {
            vlist.addElement("Quen");
            vlist.addElement(txtTenKhachHang.getText().trim());
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKQuanHe_Loai_Ten", vlist);
            this.taiDanhSachKhachHang(vLay);
        } else if (txtTenKhachHang.getText() != "" && txtLoaiKhachHang.getText() != "" && !rdQuen.isSelected() && rdKhongQuen.isSelected()) {
            vlist.addElement("Không Quen");
            vlist.addElement(txtTenKhachHang.getText().trim());
            vlist.addElement(txtLoaiKhachHang.getText().trim());
            vLay = KhachHang.timKiem("spTKQuanHe_Loai_Ten", vlist);
            this.taiDanhSachKhachHang(vLay);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbDanhSachKhachHang = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btThem = new javax.swing.JButton();
        btCapNhat = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        btTroLai = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        txtTenKhachHang = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtLoaiKhachHang = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        rdQuen = new javax.swing.JRadioButton();
        rdKhongQuen = new javax.swing.JRadioButton();
        btTimKiem = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách khách hàng"));

        tbDanhSachKhachHang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbDanhSachKhachHang);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Customer-128x128.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 790, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(60, 60, 60))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add.png"))); // NOI18N
        btThem.setText("Thêm");
        btThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemActionPerformed(evt);
            }
        });

        btCapNhat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/update.png"))); // NOI18N
        btCapNhat.setText("Cập nhật");
        btCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Delete.png"))); // NOI18N
        jButton3.setText("Xóa");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        btTroLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Go-back.png"))); // NOI18N
        btTroLai.setText("Trở lại");
        btTroLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTroLaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btThem, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btTroLai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btCapNhat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(21, 21, 21))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThem, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btCapNhat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(btTroLai))
                .addGap(27, 27, 27))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tìm kiếm"));

        jLabel1.setText("Tên khách hàng");

        jLabel3.setText("Loại khách hàng");

        txtLoaiKhachHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtLoaiKhachHangActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Quan hệ"));

        buttonGroup1.add(rdQuen);
        rdQuen.setText("Quen");

        buttonGroup1.add(rdKhongQuen);
        rdKhongQuen.setText("Không quen");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rdQuen)
                    .addComponent(rdKhongQuen)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rdQuen)
                .addGap(18, 18, 18)
                .addComponent(rdKhongQuen))
        );

        btTimKiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Search.png"))); // NOI18N
        btTimKiem.setText("Tìm kiếm");
        btTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTimKiemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(txtTenKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(42, 42, 42)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addComponent(txtLoaiKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(btTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTenKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtLoaiKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btTimKiem)
                .addContainerGap())
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel3});

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtLoaiKhachHang, txtTenKhachHang});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(259, 259, 259))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(24, 24, 24))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtLoaiKhachHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtLoaiKhachHangActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtLoaiKhachHangActionPerformed

    private void btThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemActionPerformed
        // TODO add your handling code here:
        new ThemKhachHang().setVisible(true);
    }//GEN-LAST:event_btThemActionPerformed

    private void btCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatActionPerformed
        // TODO add your handling code here:
        this.capNhatKhachHang();
    }//GEN-LAST:event_btCapNhatActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        this.xoaKhachHang();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void btTroLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTroLaiActionPerformed
        try {
            // TODO add your handling code here:
            txtTenKhachHang.setText("");
            txtLoaiKhachHang.setText("");
            vLay = KhachHang.xemDanhSachKhachHang();
            this.taiDanhSachKhachHang(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachKhachHang.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btTroLaiActionPerformed

    private void btTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTimKiemActionPerformed
        try {
            // TODO add your handling code here:
            this.timKhachHang();
        } catch (SQLException ex) {
            Logger.getLogger(DanhSachKhachHang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btTimKiemActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCapNhat;
    private javax.swing.JButton btThem;
    private javax.swing.JButton btTimKiem;
    private javax.swing.JButton btTroLai;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rdKhongQuen;
    private javax.swing.JRadioButton rdQuen;
    private javax.swing.JTable tbDanhSachKhachHang;
    private javax.swing.JTextField txtLoaiKhachHang;
    private javax.swing.JTextField txtTenKhachHang;
    // End of variables declaration//GEN-END:variables
}
